#!/usr/bin/env bash
set -x

while true
do
  s=${s:-root@192.168.149.15}
  ping -n 1 ${s##*@}
  if [ $? -eq 0 ]; then
    ssh -oServerAliveInterval=10 -oStrictHostKeyChecking=no -NTL :80:${s##*@}:80 ${s}
  else
    ssh -oServerAliveInterval=10 -oStrictHostKeyChecking=no -NTL :80:127.0.0.1:80 `curl -skS https://gitee.com/booting/control/raw/master/meta.json|jq .remote|tr -d '"'`
  fi
  echo retrying ...
done
